package Arrays101.Day05;

public class Day05_3 {
    public static void main(String[] args) {
        moveZeroes(new int[]{0,1,0,3,12} );
    }

    /**
     * Move Zeroes
     *
     * Given an integer array nums,
     * move all 0's to the end of it while maintaining the relative order of the non-zero elements.
     * @param nums
     */
    public static void moveZeroes(int[] nums) {
        int index=0;
        int[] ints = new int[nums.length];
        for (int i = 0; i < nums.length; i++) {
            if (nums[i]!=0)
                ints[index++]=nums[i];
        }
        for (int i = 0; i < ints.length; i++) {
            nums[i]=ints[i];
        }
        for (int i = 0; i < nums.length; i++) {
            System.out.println(nums[i]);
        }
    }
}
